/*
 * PostHandler.h
 *
 *  Created on: 24/06/2014
 *      Author: Vitor
 */

#ifndef POSTHANDLER_H_
#define POSTHANDLER_H_

#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include "HttpRequest.h"
#include "ByteQueue.h"

class PostHandler {
private:
	// Presume-se que o m�todo receive_request() j� foi chamado.
	HttpRequest request;
	std::map<std::string, std::vector<char>> data;
	std::map<std::string, std::string> filename_mapper;

	void extract_data();
	void extract_multipart_data();
	void extract_normal_data();
	void parse_multipart_element(std::vector<char>& element_data);
	std::string get_boundary();

public:
	PostHandler(HttpRequest request);
	virtual ~PostHandler();

	std::vector<char>& get_value(std::string name) {
		return data[name];
	}
	bool has_value(std::string name) {
		return data.count(name);
	}
	std::string get_filename(std::string name) {
		return filename_mapper[name];
	}
};

#endif /* POSTHANDLER_H_ */
